package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-01-13 00:05
 **/
public class LeetCode747 {

    public int dominantIndex(int[] nums) {
        int firstIndex = 0;
        int second = -1;
        for (int i = 1; i < nums.length; ++i) {
            if (nums[i] > nums[firstIndex]) {
                second = nums[firstIndex];
                firstIndex = i;
            } else if (nums[i] > second) {
                second = nums[i];
            }
        }

        return nums[firstIndex] >= second * 2 ? firstIndex : -1;
    }

}
